/*
Copyright SecureKey Technologies Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package random

import (
	"math/rand"

	"git.cloud.inspur.com/ichain/ichain-sdk-go/pkg/providers/ichain"
	"github.com/pkg/errors"
)

type Balancer struct {
}

func NewBalancer() *Balancer {
	return &Balancer{}
}

func (b *Balancer) Choose(inodes []ichain.Inode) (ichain.Inode, error) {
	if len(inodes) == 0 {
		return nil, errors.New("no inodes")
	}

	index := rand.Intn(len(inodes))
	return inodes[index], nil
}
